/*!
 * \file frget_absdir.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = 0;
    char *p_relative_path = (char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c";
    unsigned int ui_size = strlen((char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c");
    char *p_abs_dir = NULL;

    p_abs_dir = (char *)frmalloc(ui_size);
    memset(p_abs_dir, 0x00, ui_size);

    i_ret = frget_absdir(p_relative_path, p_abs_dir, ui_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    CU_ASSERT(memcmp(p_abs_dir,p_relative_path,strlen(p_abs_dir)) == 0);
    frfree(p_abs_dir);

}


static void __case2(void)
{
    int i_ret = 0;
    char *p_relative_path = NULL;
    char *p_abs_dir = NULL;
    char *p_cmp = NULL;
    unsigned int ui_size = strlen((char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c");

    p_abs_dir = (char *)frmalloc(ui_size);
    memset(p_abs_dir,'\0',ui_size);

    i_ret = frget_absdir(p_relative_path, p_abs_dir, ui_size);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    p_cmp = (char *)frmalloc(ui_size);
    memset(p_cmp,'\0',ui_size);

    CU_ASSERT(memcmp(p_abs_dir,p_cmp,ui_size) == 0);
    frfree(p_abs_dir);
    frfree(p_cmp);

}


static void __case3(void)
{
    int i_ret = 0;
    unsigned int ui_size = 5;
    char *p_relative_path = (char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c";
    char *p_abs_dir = NULL;
    char *p_cmp = NULL;

    p_abs_dir = (char *)frmalloc(ui_size);
    memset(p_abs_dir,'\0',ui_size);

    i_ret = frget_absdir(p_relative_path, p_abs_dir, ui_size);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    p_cmp = (char *)frmalloc(ui_size);
    memset(p_cmp,'\0',ui_size);
    CU_ASSERT(memcmp(p_abs_dir,p_cmp,ui_size) == 0);
    frfree(p_abs_dir);
    frfree(p_cmp);

}

static void __case4(void)
{
    int i_ret = 0;
    char *p_relative_path = (char *)"t_frsutl/t_frame_get_absdir.c";
    char *p_abs_dir = NULL;
    char *p_cmp = (char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c";
    unsigned int ui_size = strlen((char *)"/mnt/hgfs/analyze/protocol_analyzer/test/apmcomm/t_frsutl/t_frame_get_absdir.c");


    p_abs_dir = (char *)frmalloc(ui_size);
    memset(p_abs_dir,'\0',ui_size);

    i_ret = frget_absdir(p_relative_path, p_abs_dir, ui_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    CU_ASSERT(memcmp(p_abs_dir,p_cmp,strlen(p_abs_dir)) == 0);
    frfree(p_abs_dir);

}



int add_suite_frget_absdir(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frsutl frget_absdir()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;
}
